package com.liaozibo.mybatis.plus.demo.framework.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 参考 <a href="https://gitee.com/baomidou/SpringWind/blob/spring-mvc/SpringWind/src/main/java/com/baomidou/springwind/controller/PermissionController.java">SpringWind</a>
 * @Author: liaozibo
 * @since: 2021/3/30
 **/
public class SuperController {

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    /**
     * <p>
     * 获取分页对象
     * </p>
     */
    protected <T> Page<T> getPage() {
        return getPage(10);
    }

    /**
     * <p>
     * 获取分页对象
     * </p>
     *
     * @param size
     *            每页显示数量
     * @return
     */
    protected <T> Page<T> getPage(int size) {
        int _size = size, _index = 1;
        if (request.getParameter("_size") != null) {
            _size = Integer.parseInt(request.getParameter("_size"));
        }
        if (request.getParameter("_index") != null) {
            _index = Integer.parseInt(request.getParameter("_index"));
        }
        return new Page<T>(_index, _size);
    }

}
